package com.bringway.framework.util;

import java.io.BufferedOutputStream;
import java.io.CharArrayWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.Writer;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.collections.iterators.EmptyIterator;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.poi2.hssf.usermodel.HSSFWorkbook;
import org.springframework.core.io.Resource;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.support.JdbcUtils;

import com.bringway.framework.domain.ArrayIterator;
import com.bringway.framework.domain.ResultSetIterator;
import com.bringway.framework.domain.SimpleExcelDataModel;
import com.bringway.framework.exception.ServiceException;


public class ExcelXmlExportUtils {
	public static void export(Resource templateFile, String outputFileName,
			Map parameters, HttpServletResponse response) {
		try {
			CharArrayWriter writer = new CharArrayWriter(1024 *32);
			response.reset();
			//response.setContentType("application/octet-stream");
			response.setContentType("application/vnd.ms-excel");
			response.setHeader("Content-Disposition", "attachment;filename="
					+ new String(outputFileName.getBytes("GBK"), "ISO-8859-1"));
			export(templateFile, parameters,writer);
			response.getOutputStream().write(writer.toString().getBytes("UTF-8"));
			response.flushBuffer();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void export(String templateFileName, String outputFileName, Map parameters,
			HttpServletResponse response) {
		CharArrayWriter writer = new CharArrayWriter(1024 *32);
		try {
			response.reset();
			response.setContentType("application/octet-stream; charset=UTF-8");
			response.setHeader("Content-Disposition", "attachment;filename="
					+ new String(outputFileName.getBytes("GBK"), "ISO-8859-1"));
		
			VelocityUtils.export(templateFileName, parameters, writer);
			response.getOutputStream().write(writer.toString().getBytes("UTF-8"));
			response.flushBuffer();
		} catch (Exception e) {
			throw new ServiceException("导出失败", e);
		} finally {
			writer.close();
		}
	}

	public static void export(Resource templateFile, Map parameters,
			Writer writer) throws Exception {
		VelocityUtils.export(templateFile, parameters, writer);
	}

	public static void export(HSSFWorkbook workbook,String title,
			 HttpServletResponse response) throws Exception {
		response.reset();
//		response.setContentType("application/octet-stream");
		 response.setContentType("application/vnd.ms-excel");
		response.setHeader("Content-Disposition", "attachment;filename="
				+ new String(title.getBytes("GBK"),
				"ISO-8859-1"));
		OutputStream os = response.getOutputStream();
		workbook.write(os);
		os.flush();
	}
	
	public static void export(SimpleExcelDataModel[] models,
			HttpServletResponse response) {

		try {
			response.reset();
			response.setContentType("application/octet-stream");
			// response.setContentType("application/vnd.ms-excel");
			response.setHeader("Content-Disposition", "attachment;filename="
					+ new String(models[0].getOutputFileName().getBytes("GBK"),
							"ISO-8859-1"));
			export(models, response.getOutputStream());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void export(SimpleExcelDataModel model,final int count, final ResultSet rs,
			HttpServletResponse response) {

		try {
			response.reset();
			response.setContentType("application/octet-stream");
			// response.setContentType("application/vnd.ms-excel");
			response.setHeader("Content-Disposition", "attachment;filename="
					+ new String(model.getOutputFileName().getBytes("GBK"),
							"ISO-8859-1"));
			export(model, count,rs,response.getOutputStream());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}


	public static void export(final SimpleExcelDataModel model,
			final int count, final ResultSet rs, final OutputStream os)
			throws Exception {
		int max = 60000;

		final PrintStream stream = new PrintStream(
				new BufferedOutputStream(os), true, "UTF-8");
		stream.print(getHeader());
		stream.print(getStyle());
		String sheetName = model.getSheetName();
		
		if (count > max) {
			for (int i = 0; i < (int) ((count / max) + 1); i++) {
				final String realSheetName = sheetName + "-" + (i + 1);

				ResultSetIterator resultSetIterator = new ResultSetIterator(rs,max,
						new RowMapper() {

							public Object mapRow(ResultSet rs, int rowNum)
									throws SQLException {
								ResultSetMetaData rsmd = rs.getMetaData();
								int columnCount = rsmd.getColumnCount();
								Object[] mapOfColValues = new Object[columnCount];
								for (int i = 0; i < columnCount; i++) {
									Object obj = JdbcUtils.getResultSetValue(
											rs, i+1);
									mapOfColValues[i] = obj;
								}
								return mapOfColValues;
							}
						});
				model.setSheetName(realSheetName);
				model.setIterator(resultSetIterator);
				try {
					fillData(model, stream);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		} else {
			final String realSheetName = sheetName ;

			ResultSetIterator resultSetIterator = new ResultSetIterator(rs,
					new RowMapper() {
						public Object mapRow(ResultSet rs, int rowNum)
								throws SQLException {
							ResultSetMetaData rsmd = rs.getMetaData();
							int columnCount = rsmd.getColumnCount() ;
							Object[] mapOfColValues = new Object[columnCount];
							for (int i = 0; i < columnCount; i++) {
								Object obj = JdbcUtils.getResultSetValue(rs,
										i+1);
								mapOfColValues[i] = obj;
							}
							return mapOfColValues;
						}
					});
			model.setSheetName(realSheetName);
			model.setIterator(resultSetIterator);
			try {
				fillData(model, stream);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		stream.print(getFooter());
		stream.flush();
		
//		if (rs!=null){
//			try{
//				JdbcUtils.closeStatement(rs.getStatement());
//				JdbcUtils.closeResultSet(rs);
//			}catch (Exception e) {
//			}
//		}
		
	}

	public static void export(SimpleExcelDataModel[] models, OutputStream os)
			throws Exception {
		OutputStream os2 = new BufferedOutputStream(os);
		os.write(getHeader().getBytes());
		os.write(getStyle().getBytes());
		int len = models.length;
		for (int i = 0; i < len; i++) {
			SimpleExcelDataModel model = models[i];
			if (model.getData() == null) {
				model.setIterator(EmptyIterator.INSTANCE);
			} else {
				model.setIterator(new ArrayIterator(model.getData()));
			}
			fillData(model, new PrintStream(os2, true, "UTF-8"));
		}
		os.write(getFooter().getBytes());
		os.flush();
	}

	public static void fillData(SimpleExcelDataModel model, PrintStream os)
			throws IOException {
		exportTitle(model, os);
		exportData(model, os);
	}

	public static void exportTitle(SimpleExcelDataModel model, PrintStream os)
			throws IOException {
		int colSize = model.getComplexTitles()[0].length;

		String sheetName = "<Worksheet ss:Name=\"" + model.getSheetName()
				+ "\">";
		os.println(sheetName);

		String tableHeader = "<Table>";
		os.println(tableHeader);

		os.println("<Row>");
		os.print("<Cell ss:Index=\"1\" ss:MergeAcross=\"");
		os.print(String.valueOf(colSize - 1));
		os.print("\"  ss:StyleID=\"title\">");
		os.print("<Data ss:Type=\"String\">");
		os.print(model.getTitle());
		os.print("</Data></Cell>");
		os.println("</Row>");

		if (model.getCorpName() != null) {
			String comment = "查询单位：" + model.getCorpName()
					+ "             查询日期：" + model.getDate();
			if (StringUtils.isNotEmpty(model.getUnit())) {
				comment += "         金额单位：" + model.getUnit();
			}

			os.println("<Row>");
			os.print("<Cell ss:Index=\"1\" ss:MergeAcross=\"");
			os.print(String.valueOf(colSize - 1));
			os.print("\">");
			os.print("<Data ss:Type=\"String\">");
			os.print(comment);
			os.println("</Data></Cell>");
			os.println("</Row>");
		}

		if (model.getExtraInfo() != null && model.getExtraInfo().length > 0) {
			for (int i = 0; i < model.getExtraInfo().length; i++) {
				os.println("<Row>");
				os.print("<Cell ss:Index=\"1\" ss:MergeAcross=\"");
				os.print(String.valueOf(colSize - 1));
				os.print("\">");
				os.print("<Data ss:Type=\"String\">");
				os.print(model.getExtraInfo()[i]);
				os.println("</Data></Cell>");
				os.println("</Row>");
			}
		}

		if (!ArrayUtils.isEmpty(model.getComplexTitles())) {
			// 合并表头
			model.merge();
			String style = "default";
			for (int i = 0; i < model.getComplexTitles().length; i++) {
				os.println("<Row>");
				boolean indexed = false;
				for (int j = 0; j < model.getComplexTitles()[i].length; j++) {
					if (StringUtils.isEmpty(model.getComplexTitles()[i][j])) {
						continue;
					}
					int mergeAcross = model.getMergeAcross(i, j);
					int mergeDown = model.getMergeDown(i, j);
					os.print("<Cell");
					if (!indexed) {
						if (j == 0) {
							os.print(" ss:Index=\"1\"");
						} else {
							os.print(" ss:Index=\"" + (j + 1) + "\"");
						}
						// indexed = true;
					}
					if (mergeAcross > 0) {
						os.print(" ss:MergeAcross=\"");
						os.print(String.valueOf(mergeAcross));
						os.print("\"");
					}
					if (mergeDown > 0) {
						os.print(" ss:MergeDown=\"");
						os.print(String.valueOf(mergeDown));
						os.print("\"");
					}

					// if (i == 0) {
					// if (j == 0) {
					// style = "leftTop";// 上边框
					// } else if (j == colSize - 1 || j==colSize-1-mergeAcross)
					// {
					// style = "rightTop";
					// } else {
					// style = "top";
					// }
					// } else if (i == rowSize - 1) {
					// if (j == 0) {
					// style = "lefBottom";// 上边框
					// } else if (j == colSize - 1 || j==colSize-1-mergeAcross)
					// {
					// style = "rightBottom";
					// } else {
					// style = "bottom";
					// }
					// } else {
					// if (j == 0) {
					// style = "left";// 上边框
					// } else if (j == colSize - 1|| j==colSize-1-mergeAcross) {
					// style = "right";
					// } else {
					// style = "default";
					// }
					// }

					os.print("  ss:StyleID=\"" + style + "\"");

					os.print(">");
					os.print("<Data ss:Type=\"String\">");
					os.print(model.getComplexTitles()[i][j]);
					os.println("</Data></Cell>");
				}
				os.println("</Row>");
			}

		}
	}

	public static void exportData(SimpleExcelDataModel model, PrintStream os)
			throws IOException {
		int colSize = model.getComplexTitles()[0].length;
		// int rowSize = model.getData().length;
		// Object[][] data = model.getData();
		Iterator iter = model.getIterator();
		DecimalFormat format = null;
		String style = "default2";
		for (int i = 0; iter.hasNext(); i++) {
			// if (i>=3){
			// break;
			// }
			try {
				Object[] objs = (Object[]) iter.next();

				os.println("<Row>");
				for (int j = 0; j < colSize; j++) {
					Object obj = objs[j];
					if (j == 0) {
						os.print("<Cell ss:Index=\"1\"");
					} else {
						os.print("<Cell");
					}

					// if (i == 0) {
					// if (j == 0) {
					// style = "leftTop2";// 上边框
					// } else if (j == colSize - 1 ) {
					// style = "rightTop2";
					// } else {
					// style = "top2";
					// }
					// } else if (i == rowSize - 1) {
					// if (j == 0) {
					// style = "lefBottom2";// 上边框
					// } else if (j == colSize - 1) {
					// style = "rightBottom2";
					// } else {
					// style = "bottom2";
					// }
					// } else {
					// if (j == 0) {
					// style = "left2";// 上边框
					// } else if (j == colSize - 1) {
					// style = "right2";
					// } else {
					// style = "default2";
					// }
					// }

					os.print("  ss:StyleID=\"" + style + "\">");

					if (obj instanceof BigDecimal) {

						if (model.getScale() != null) {
							int scale = model.getScale()[j];
							scale = scale < 10 ? scale : 2;
							String scaleString = "";
							if (scale > 0) {
								scaleString = "."
										+ StringUtils.repeat("0", scale);
								;
							}
							format = new DecimalFormat(
									"###,###,###,###,###,##0" + scaleString);
						} else {
							// if (o instanceof BigDecimal) {
							// BigDecimal value = (BigDecimal) o;
							// int scale = value.scale();
							// scale = scale < 10 ? scale : 2;
							// String scaleString = "";
							// if (scale > 0) {
							// scaleString = "." + StringUtils.repeat("0",
							// scale);
							// ;
							// }
							// format = new
							// DecimalFormat("###,###,###,###,###,##0" +
							// scaleString);
							// } else {
							format = new DecimalFormat(
									"###,###,###,###,###,##0.00");
							// }
						}
						os.print("<Data ss:Type=\"String\">");
						os.print(format
								.format(((BigDecimal) obj).doubleValue()));
					} else if (obj instanceof Float) {
						format = new DecimalFormat("###,###,###,###,###,##0.00");
						os.print("<Data ss:Type=\"String\">");
						os.print(format.format(((Float) obj).doubleValue()));
					} else if (obj instanceof Double) {
						format = new DecimalFormat("###,###,###,###,###,##0.00");
						os.print("<Data ss:Type=\"String\">");
						os.print(format.format(((Double) obj).doubleValue()));
					} else if (obj != null) {
						os.print("<Data ss:Type=\"String\">");
						String temp = obj.toString();
						temp = temp.replaceAll("&", "&amp;");
						temp = temp.replaceAll(">", "&gt;");
						temp = temp.replaceAll("<", "&lt;");
						temp = temp.replaceAll("\"", "&quot;");

						os.print(temp);
					} else {
						os.print("<Data ss:Type=\"String\">");
					}
					os.println("</Data></Cell>");
				}
				os.println("</Row>");

			} catch (Exception e) {
				e.printStackTrace();
				break;
			}

		}
		// 打印合计信息
		if (model.getSumInfo() != null) {
			Object[] objs = model.getSumInfo();

			os.println("<Row>");
			for (int j = 0; j < colSize; j++) {
				Object obj = objs[j];
				if (j == 0) {
					os.print("<Cell ss:Index=\"1\"");
				} else {
					os.print("<Cell");
				}

				// if (i == 0) {
				// if (j == 0) {
				// style = "leftTop2";// 上边框
				// } else if (j == colSize - 1 ) {
				// style = "rightTop2";
				// } else {
				// style = "top2";
				// }
				// } else if (i == rowSize - 1) {
				// if (j == 0) {
				// style = "lefBottom2";// 上边框
				// } else if (j == colSize - 1) {
				// style = "rightBottom2";
				// } else {
				// style = "bottom2";
				// }
				// } else {
				// if (j == 0) {
				// style = "left2";// 上边框
				// } else if (j == colSize - 1) {
				// style = "right2";
				// } else {
				// style = "default2";
				// }
				// }

				os.print("  ss:StyleID=\"" + style + "\">");

				if (obj instanceof BigDecimal) {

					if (model.getScale() != null) {
						int scale = model.getScale()[j];
						scale = scale < 10 ? scale : 2;
						String scaleString = "";
						if (scale > 0) {
							scaleString = "." + StringUtils.repeat("0", scale);
							;
						}
						format = new DecimalFormat("###,###,###,###,###,##0"
								+ scaleString);
					} else {
						// if (o instanceof BigDecimal) {
						// BigDecimal value = (BigDecimal) o;
						// int scale = value.scale();
						// scale = scale < 10 ? scale : 2;
						// String scaleString = "";
						// if (scale > 0) {
						// scaleString = "." + StringUtils.repeat("0",
						// scale);
						// ;
						// }
						// format = new
						// DecimalFormat("###,###,###,###,###,##0" +
						// scaleString);
						// } else {
						format = new DecimalFormat("###,###,###,###,###,##0.00");
						// }
					}
					os.print("<Data ss:Type=\"String\">");
					os.print(format.format(((BigDecimal) obj).doubleValue()));
				} else if (obj instanceof Float) {
					format = new DecimalFormat("###,###,###,###,###,##0.00");
					os.print("<Data ss:Type=\"String\">");
					os.print(format.format(((Float) obj).doubleValue()));
				} else if (obj instanceof Double) {
					format = new DecimalFormat("###,###,###,###,###,##0.00");
					os.print("<Data ss:Type=\"String\">");
					os.print(format.format(((Double) obj).doubleValue()));
				} else if (obj != null) {
					os.print("<Data ss:Type=\"String\">");
					String temp = obj.toString();
					temp = temp.replaceAll("&", "&amp;");
					temp = temp.replaceAll(">", "&gt;");
					temp = temp.replaceAll("<", "&lt;");
					temp = temp.replaceAll("\"", "&quot;");

					os.print(temp);
				} else {
					os.print("<Data ss:Type=\"String\">");
				}
				os.println("</Data></Cell>");
			}
			os.println("</Row>");
		}
		String tableFooter = "</Table>";
		os.println(tableFooter);

		String sheetFooter = "</Worksheet>";
		os.println(sheetFooter);
		os.flush();
	}

	// private static void exportData(SimpleExcelDataModel model, ResultSet rs,
	// PrintStream os) throws IOException,
	// SQLException {
	// int colSize = rs.getMetaData().getColumnCount();
	// //int rowSize = rs.getFetchSize();
	// DecimalFormat format = null;
	// int i=-1;
	// while (rs.next()) {
	// i++;
	// os.println("<Row>");
	// String style = "default";
	// for (int j = 0; j < colSize; j++) {
	// if (j == 0) {
	// os.print("<Cell ss:Index=\"1\"");
	// } else {
	// os.print("<Cell");
	// }
	//				
	// if (i == 0) {
	// if (j == 0) {
	// style = "leftTop";// 上边框
	// } else if (j == colSize - 1 ) {
	// style = "rightTop";
	// } else {
	// style = "top";
	// }
	// } else if (i == rowSize - 1) {
	// if (j == 0) {
	// style = "lefBottom";// 上边框
	// } else if (j == colSize - 1) {
	// style = "rightBottom";
	// } else {
	// style = "bottom";
	// }
	// } else {
	// if (j == 0) {
	// style = "left";// 上边框
	// } else if (j == colSize - 1) {
	// style = "right";
	// } else {
	// style = "default";
	// }
	// }
	//
	// os.print(" ss:StyleID=\"" + style + "\">");
	//
	//
	// Object obj = rs.getObject(j+1);
	//
	// if (obj instanceof BigDecimal) {
	//
	// if (model.getScale() != null) {
	// int scale = model.getScale()[j];
	// scale = scale < 10 ? scale : 2;
	// String scaleString = "";
	// if (scale > 0) {
	// scaleString = "." + StringUtils.repeat("0", scale);
	// ;
	// }
	// format = new DecimalFormat("###,###,###,###,###,##0" + scaleString);
	// } else {
	// format = new DecimalFormat("###,###,###,###,###,##0.00");
	// }
	// os.print("<Data ss:Type=\"Number\">");
	// os.print(format.format(((BigDecimal) obj).doubleValue()));
	// } else if (obj instanceof Float) {
	// os.print("<Data ss:Type=\"Number\">");
	// os.print(obj);
	// } else if (obj instanceof Double) {
	// os.print("<Data ss:Type=\"Number\">");
	// os.print(obj);
	// } else if (obj != null) {
	// os.print("<Data ss:Type=\"String\">");
	// os.print(obj);
	// }
	// os.println("</Data></Cell>");
	// }
	// os.println("</Row>");
	// }
	//
	// String tableFooter = "</Table>";
	// os.println(tableFooter);
	//
	// String sheetFooter = "</Worksheet>";
	// os.println(sheetFooter);
	// }

	public static String getHeader() {
		return "<?xml version=\"1.0\"?>"
				+ "\n"
				+ "<?mso-application progid=\"Excel.Sheet\"?>"
				+ "\n"
				+ "<Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\""
				+ "\n" + " xmlns:o=\"urn:schemas-microsoft-com:office:office\""
				+ "\n" + " xmlns:x=\"urn:schemas-microsoft-com:office:excel\""
				+ "\n"
				+ " xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\""
				+ "\n" + " xmlns:html=\"http://www.w3.org/TR/REC-html40\">"
				+ "\n";
	}

	public static String getFooter() {
		return "\n</Workbook>\n";
	}

	public static String getStyle() {
		return "<Styles>"
				+ "\n"

				+ "<Style ss:ID=\"title\">"
				+ "\n"
				+ "  <Alignment ss:Horizontal=\"Center\" ss:Vertical=\"Bottom\"/>"
				+ "\n"
				+ "  <Font ss:FontName=\"SimSun\" ss:Size=\"20\" ss:Bold=\"1\"/>"
				+ "\n"
				+ "</Style>"
				+ "\n"

				+ "<Style ss:ID=\"leftTop\">"
				+ "\n"
				+ "<Alignment ss:Horizontal=\"Center\" ss:Vertical=\"Center\"/>"
				+ "\n"
				+ "<Borders>"
				+ "\n"
				+ "<Border ss:Position=\"Bottom\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"  ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Left\" ss:LineStyle=\"Continuous\" ss:Weight=\"3\"  ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Right\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\" ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Top\" ss:LineStyle=\"Continuous\" ss:Weight=\"3\"   ss:Color=\"#000000\"/>"
				+ "\n"
				+ "</Borders>"
				+ "\n"
				+ "</Style>"
				+ "\n"

				+ "<Style ss:ID=\"left\">"
				+ "\n"
				+ "<Alignment ss:Horizontal=\"Center\" ss:Vertical=\"Center\"/>"
				+ "\n"
				+ "<Borders>"
				+ "\n"
				+ "<Border ss:Position=\"Bottom\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"  ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Left\" ss:LineStyle=\"Continuous\" ss:Weight=\"3\"   ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Right\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"  ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Top\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"  ss:Color=\"#000000\"/>"
				+ "\n"
				+ "</Borders>"
				+ "\n"
				+ "</Style>"
				+ "\n"

				+ "<Style ss:ID=\"lefBottom\">"
				+ "\n"
				+ "<Alignment ss:Horizontal=\"Center\" ss:Vertical=\"Center\"/>"
				+ "\n"
				+ "<Borders>"
				+ "\n"
				+ "<Border ss:Position=\"Bottom\" ss:LineStyle=\"Continuous\" ss:Weight=\"3\" ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Left\" ss:LineStyle=\"Continuous\" ss:Weight=\"3\"  ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Right\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"   ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Top\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"   ss:Color=\"#000000\"/>"
				+ "\n"
				+ "</Borders>"
				+ "\n"
				+ "</Style>"
				+ "\n"

				+ "<Style ss:ID=\"bottom\">"
				+ "\n"
				+ "<Alignment ss:Horizontal=\"Center\" ss:Vertical=\"Center\"/>"
				+ "\n"
				+ "<Borders>"
				+ "\n"
				+ "<Border ss:Position=\"Bottom\" ss:LineStyle=\"Continuous\" ss:Weight=\"3\" ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Left\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"  ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Right\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"  ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Top\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"   ss:Color=\"#000000\"/>"
				+ "\n"
				+ "</Borders>"
				+ "\n"
				+ "</Style>"
				+ "\n"

				+ "<Style ss:ID=\"rightBottom\">"
				+ "\n"
				+ "<Alignment ss:Horizontal=\"Center\" ss:Vertical=\"Center\"/>"
				+ "\n"
				+ "<Borders>"
				+ "\n"
				+ "<Border ss:Position=\"Bottom\" ss:LineStyle=\"Continuous\" ss:Weight=\"3\" ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Left\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"   ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Right\" ss:LineStyle=\"Continuous\" ss:Weight=\"3\"  ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Top\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"  ss:Color=\"#000000\"/>"
				+ "\n"
				+ "</Borders>"
				+ "\n"
				+ "</Style>"
				+ "\n"

				+ "<Style ss:ID=\"right\">"
				+ "\n"
				+ "<Alignment ss:Horizontal=\"Center\" ss:Vertical=\"Center\"/>"
				+ "\n"
				+ "<Borders>"
				+ "\n"
				+ "<Border ss:Position=\"Bottom\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\" ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Left\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\" ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Right\" ss:LineStyle=\"Continuous\" ss:Weight=\"3\" ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Top\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\" ss:Color=\"#000000\"/>"
				+ "\n"
				+ "</Borders>"
				+ "\n"
				+ "</Style>"
				+ "\n"

				+ "<Style ss:ID=\"rightTop\">"
				+ "\n"
				+ "<Alignment ss:Horizontal=\"Center\" ss:Vertical=\"Center\"/>"
				+ "\n"
				+ "<Borders>"
				+ "\n"
				+ "<Border ss:Position=\"Bottom\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\" ss:Color=\"#000000\"/>"
				+ "\n"
				+ " <Border ss:Position=\"Left\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"    ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Right\" ss:LineStyle=\"Continuous\" ss:Weight=\"3\"    ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Top\" ss:LineStyle=\"Continuous\" ss:Weight=\"3\"    ss:Color=\"#000000\"/>"
				+ "\n"
				+ "</Borders>"
				+ "\n"
				+ "</Style>"
				+ "\n"

				+ "<Style ss:ID=\"top\">"
				+ "\n"
				+ "<Alignment ss:Horizontal=\"Center\" ss:Vertical=\"Center\"/>"
				+ "\n"
				+ "<Borders>"
				+ "\n"
				+ "<Border ss:Position=\"Bottom\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\" ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Left\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"   ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Right\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"  ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Top\" ss:LineStyle=\"Continuous\" ss:Weight=\"3\"   ss:Color=\"#000000\"/>"
				+ "\n"
				+ "</Borders>"
				+ "\n"
				+ "</Style>"
				+ "\n"

				+ "<Style ss:ID=\"default\">"
				+ "\n"
				+ "<Alignment ss:Horizontal=\"Center\" ss:Vertical=\"Center\"/>"
				+ "\n"
				+ "<Borders>"
				+ "\n"
				+ "<Border ss:Position=\"Bottom\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\" ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Left\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"   ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Right\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"  ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Top\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"   ss:Color=\"#000000\"/>"
				+ "\n"
				+ "</Borders>"
				+ "\n"
				+ "<Font x:Family=\"Swiss\" ss:Size=\"12\" ss:Bold=\"1\" />"
				+ "\n"
				+ "<Interior/>"
				+ "\n"
				+ "<NumberFormat/>"
				+ "\n"
				+ "<Protection/>"
				+ "\n"
				+ "</Style>"
				+ "\n"

				// --------------------

				+ "<Style ss:ID=\"leftTop2\">"
				+ "\n"
				+ "<Alignment ss:Horizontal=\"Right\" ss:Vertical=\"Bottom\"/>"
				+ "\n"
				+ "<Borders>"
				+ "\n"
				+ "<Border ss:Position=\"Bottom\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"  ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Left\" ss:LineStyle=\"Continuous\" ss:Weight=\"3\"  ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Right\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\" ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Top\" ss:LineStyle=\"Continuous\" ss:Weight=\"3\"   ss:Color=\"#000000\"/>"
				+ "\n"
				+ "</Borders>"
				+ "\n"
				+ "<Font x:Family=\"Swiss\"/>"
				+ "\n"
				+ "<Interior/>"
				+ "\n"
				+ "<NumberFormat/>"
				+ "\n"
				+ "</Style>"
				+ "\n"

				+ "<Style ss:ID=\"left2\">"
				+ "\n"
				+ "<Alignment ss:Horizontal=\"Right\" ss:Vertical=\"Bottom\"/>"
				+ "\n"
				+ "<Borders>"
				+ "\n"
				+ "<Border ss:Position=\"Bottom\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"  ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Left\" ss:LineStyle=\"Continuous\" ss:Weight=\"3\"   ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Right\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"  ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Top\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"  ss:Color=\"#000000\"/>"
				+ "\n"
				+ "</Borders>"
				+ "\n"
				+ "<Font x:Family=\"Swiss\"/>"
				+ "\n"
				+ "<Interior/>"
				+ "\n"
				+ "<NumberFormat/>"
				+ "\n"
				+ "</Style>"
				+ "\n"

				+ "<Style ss:ID=\"lefBottom2\">"
				+ "\n"
				+ "<Alignment ss:Horizontal=\"Right\" ss:Vertical=\"Bottom\"/>"
				+ "\n"
				+ "<Borders>"
				+ "\n"
				+ "<Border ss:Position=\"Bottom\" ss:LineStyle=\"Continuous\" ss:Weight=\"3\" ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Left\" ss:LineStyle=\"Continuous\" ss:Weight=\"3\"  ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Right\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"   ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Top\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"   ss:Color=\"#000000\"/>"
				+ "\n"
				+ "</Borders>"
				+ "\n"
				+ "<Font x:Family=\"Swiss\"/>"
				+ "\n"
				+ "<Interior/>"
				+ "\n"
				+ "<NumberFormat/>"
				+ "\n"
				+ "</Style>"
				+ "\n"

				+ "<Style ss:ID=\"bottom2\">"
				+ "\n"
				+ "<Alignment ss:Horizontal=\"Right\" ss:Vertical=\"Bottom\"/>"
				+ "\n"
				+ "<Borders>"
				+ "\n"
				+ "<Border ss:Position=\"Bottom\" ss:LineStyle=\"Continuous\" ss:Weight=\"3\" ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Left\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"  ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Right\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"  ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Top\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"   ss:Color=\"#000000\"/>"
				+ "\n"
				+ "</Borders>"
				+ "\n"
				+ "<Font x:Family=\"Swiss\"/>"
				+ "\n"
				+ "<Interior/>"
				+ "\n"
				+ "<NumberFormat/>"
				+ "\n"
				+ "</Style>"
				+ "\n"

				+ "<Style ss:ID=\"rightBottom2\">"
				+ "\n"
				+ "<Alignment ss:Horizontal=\"Right\" ss:Vertical=\"Bottom\"/>"
				+ "\n"
				+ "<Borders>"
				+ "\n"
				+ "<Border ss:Position=\"Bottom\" ss:LineStyle=\"Continuous\" ss:Weight=\"3\" ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Left\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"   ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Right\" ss:LineStyle=\"Continuous\" ss:Weight=\"3\"  ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Top\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"  ss:Color=\"#000000\"/>"
				+ "\n"
				+ "</Borders>"
				+ "\n"
				+ "<Font x:Family=\"Swiss\"/>"
				+ "\n"
				+ "<Interior/>"
				+ "\n"
				+ "<NumberFormat/>"
				+ "\n"
				+ "</Style>"
				+ "\n"

				+ "<Style ss:ID=\"right2\">"
				+ "\n"
				+ "<Alignment ss:Horizontal=\"Right\" ss:Vertical=\"Bottom\"/>"
				+ "\n"
				+ "<Borders>"
				+ "\n"
				+ "<Border ss:Position=\"Bottom\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\" ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Left\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\" ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Right\" ss:LineStyle=\"Continuous\" ss:Weight=\"3\" ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Top\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\" ss:Color=\"#000000\"/>"
				+ "\n"
				+ "</Borders>"
				+ "\n"
				+ "<Font x:Family=\"Swiss\"/>"
				+ "\n"
				+ "<Interior/>"
				+ "\n"
				+ "<NumberFormat/>"
				+ "\n"
				+ "</Style>"
				+ "\n"

				+ "<Style ss:ID=\"rightTop2\">"
				+ "\n"
				+ "<Alignment ss:Horizontal=\"Right\" ss:Vertical=\"Bottom\"/>"
				+ "\n"
				+ "<Borders>"
				+ "\n"
				+ "<Border ss:Position=\"Bottom\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\" ss:Color=\"#000000\"/>"
				+ "\n"
				+ " <Border ss:Position=\"Left\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"    ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Right\" ss:LineStyle=\"Continuous\" ss:Weight=\"3\"    ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Top\" ss:LineStyle=\"Continuous\" ss:Weight=\"3\"    ss:Color=\"#000000\"/>"
				+ "\n"
				+ "</Borders>"
				+ "\n"
				+ "<Font x:Family=\"Swiss\"/>"
				+ "\n"
				+ "<Interior/>"
				+ "\n"
				+ "<NumberFormat/>"
				+ "\n"
				+ "</Style>"
				+ "\n"

				+ "<Style ss:ID=\"top2\">"
				+ "\n"
				+ "<Alignment ss:Horizontal=\"Right\" ss:Vertical=\"Bottom\"/>"
				+ "\n"
				+ "<Borders>"
				+ "\n"
				+ "<Border ss:Position=\"Bottom\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\" ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Left\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"   ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Right\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"  ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Top\" ss:LineStyle=\"Continuous\" ss:Weight=\"3\"   ss:Color=\"#000000\"/>"
				+ "\n"
				+ "</Borders>"
				+ "\n"
				+ "<Font x:Family=\"Swiss\"/>"
				+ "\n"
				+ "<Interior/>"
				+ "\n"
				+ "<NumberFormat/>"
				+ "\n"
				+ "</Style>"
				+ "\n"

				/*
				 * + "<Style ss:ID=\"default\">" + "\n" + "<Alignment
				 * ss:Horizontal=\"Center\" ss:Vertical=\"Center\"/>" + "\n" + "<Borders>" +
				 * "\n" + "<Border ss:Position=\"Bottom\"
				 * ss:LineStyle=\"Continuous\" ss:Weight=\"1\"
				 * ss:Color=\"#000000\"/>" + "\n" + "<Border
				 * ss:Position=\"Left\" ss:LineStyle=\"Continuous\"
				 * ss:Weight=\"1\" ss:Color=\"#000000\"/>" + "\n" + "<Border
				 * ss:Position=\"Right\" ss:LineStyle=\"Continuous\"
				 * ss:Weight=\"1\" ss:Color=\"#000000\"/>" + "\n" + "<Border
				 * ss:Position=\"Top\" ss:LineStyle=\"Continuous\"
				 * ss:Weight=\"1\" ss:Color=\"#000000\"/>" + "\n" + "</Borders>" +
				 * "\n" + "</Style>" + "\n"
				 */
				+ "<Style ss:ID=\"default2\" ss:Name=\"Normal\">"
				+ "\n"
				+ "<Alignment ss:Horizontal=\"Center\" ss:Vertical=\"Center\"/>"
				+ "\n"
				+ "<Borders>"
				+ "\n"
				+ "<Border ss:Position=\"Bottom\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\" ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Left\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"   ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Right\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"  ss:Color=\"#000000\"/>"
				+ "\n"
				+ "<Border ss:Position=\"Top\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"   ss:Color=\"#000000\"/>"
				+ "\n" + "</Borders>" + "\n" + "<Font x:Family=\"Swiss\"/>"
				+ "\n" + "<Interior/>" + "\n" + "<NumberFormat/>" + "\n"
				+ "<Protection/>" + "\n" + "</Style>" + "\n"

				+ "</Styles>" + "\n";

	}
	public static void main(String[] args) {
		HttpServletResponse response = null;
		Map<String,String> map = new HashMap<>();
		ExcelXmlExportUtils.export("/com/suyuan/callcenter/action/repair.xml", "报修单.xls", map, response);
	}
}
